Expand description
Control log
level with a --verbose
flag for your CLI
§Examples
To get --quiet
and --verbose
flags through your entire program, just flatten
Verbosity
:
#[command(flatten)]
verbose: Verbosity,
You can then use this to configure your logger:
let cli = Cli::parse();
env_logger::Builder::new()
.filter_level(cli.verbose.log_level_filter())
.init();
By default, this will only report errors.
-q
silences output-v
show warnings-vv
show info-vvv
show debug-vvvv
show trace
You can also customize the default logging level:
use clap_verbosity_flag::{Verbosity, InfoLevel};
/// Le CLI
#[derive(Debug, Parser)]
struct Cli {
#[command(flatten)]
verbose: Verbosity<InfoLevel>,
}
Or implement our LogLevel
trait to customize the default log level and help output.
Structs§
- Default to
log::Level::Error
- Default to
log::Level::Info
- Logging flags to
#[command(flatten)]
into your CLI - Default to
log::Level::Warn
Enums§
- An enum representing the available verbosity levels of the logger.
- An enum representing the available verbosity level filters of the logger.
Traits§
- Customize the default log-level and associated help